from rest_framework import serializers
from myapp.models import *


class RoleSer(serializers.ModelSerializer):
    class Meta:
        model = RoleModel
        fields = '__all__'


class RankSer(serializers.ModelSerializer):
    class Meta:
        model = RankModel
        fields = '__all__'



class RoleMenuSer(serializers.ModelSerializer):
    role = serializers.PrimaryKeyRelatedField(queryset=RoleModel.objects.all())
    role_name = serializers.SerializerMethodField()
    menu = serializers.PrimaryKeyRelatedField(queryset=MenuModel.objects.all())
    menu_name = serializers.SerializerMethodField()

    def get_role_name(self,obj):
        return obj.role.name

    def get_menu_name(self,obj):
        return obj.menu.m_name

    class Meta:
        model = RoleMenuModel
        fields = '__all__'


class DepartmentSer(serializers.ModelSerializer):
    class Meta:
        model = DepartmentModel
        fields = '__all__'

class JobsSer(serializers.ModelSerializer):
    class Meta:
        model = JobsModel
        fields = '__all__'